{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww25100\viewh14180\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 /* bounce1d.c\
 *	purpose	animation with user controlled speed and direction\
 *	note	the handler does the animation\
 *		the main program reads keyboard input\
 *	compile	cc bounce1d.c set_ticker.c -lcurses -o bounce1d\
 *
 */\
#include	<stdio.h>\
#include	<curses.h>\
#include	<signal.h>\
#include    <string.h>\
\
/* some global settings main and the handler use */\
\
#define	MESSAGE	"hello"\
#define BLANK   "     "\
\
int	row;	/* current row		*/\
int	col;	/* current column	*/\
int	dir;	/* where we are going	*/\
\
int main()\
\{\
    int	delay;		/* bigger => slower	*/\
    int	ndelay;		/* new delay		*/\
    int	c;		/* user input		*/\
    void	move_msg(int);	/* handler for timer	*/\
\
    initscr();\
    crmode();\
    noecho();\
    clear();\
\
    row   = 10;		/* start here		*/\
    col   = 0;\
    dir   = 1;		/* add 1 to row number	*/\
    delay = 200;		/* 200ms = 0.2 seconds  */\
\
    move(row,col);		/* get into position	*/\
    addstr(MESSAGE);	/* draw message		*/\
    signal(SIGALRM, move_msg );\
    set_ticker( delay );\
\
    while(1)\
    \{\
        ndelay = 0;\
        c = getch();\
        if ( c == 'q' ) break;\
        if ( c == ' ' ) dir = -dir;\
        if ( c == 'f' && delay > 2 ) ndelay = delay/2;\
        if ( c == 's' ) ndelay = delay * 2 ;\
        if ( ndelay > 0 )\
            set_ticker( delay = ndelay );\
    \}\
    endwin();\
    return 0;\
\}\
\
void move_msg(int signum)\
\{\
    signal(SIGALRM, move_msg);	/* reset, just in case	*/\
    move( row, col );\
    addstr( BLANK );\
    col += dir;			/* move to new column	*/\
    move( row, col );		/* then set cursor	*/\
    addstr( MESSAGE );		/* redo message		*/\
    refresh();			/* and show it		*/\
\
    /*\
     * now handle borders\
     */\
    if ( dir == -1 && col <= 0 )\
        dir = 1;\
    else if ( dir == 1 && col+strlen(MESSAGE) >= COLS )\
        dir = -1;\
\}\
b}